layui.use(['layer','form','jquery'],function () {
    var layer=layui.layer,
        form=layui.form,
        $=layui.jquery;
    form.on('submit(formDemo)', function(data){
        $.ajax({
            type:"post",
            url:"user/reg",
            data:{
                "phone":data.field.phone,
                "verifyCode":data.field.verifyCode,
                "username":data.field.username,
                "password":data.field.password
            },
            dataType:"json",
            success:function(msg){
                $("#resetBtn").click();
                if (msg.code==0){
                    window.location.href="/login.html";
                }else {
                    alert(msg.msg);
                    alert(msg.msg());
                }
            }
        })
        return false;
    });
    $("#smsbtn").click(function(){
        var phone = $("input[name=phone]").val();
        if (phone.length < 11){
            alert("请输入正确的手机号..")
            return ;
        }
        $.ajax({
            type:"post",
            url:"user/sendSms",
            data:{
                "phone":$("input[name=phone]").val()
            },
            dataType:"json",
            success:function(msg){
                alert("发送成功");
            }
        })
    });
    $("#username").blur(function () {
        $.ajax({
            type:"post",
            url:"user/check",
            data:{
                "username":$("#username").val()
            },
            dataType:"json",
            success:function(msg){
                if (msg.code==0){
                    $("#check").text(msg.msg);
                    $("#check").css("color","green");
                }else {
                    $("#check").text(msg.msg);
                    $("#check").css("color","red");
                }
            }
        })
    });
});